import Link from "next/link"; import { notFound } from "next/navigation"; import { ArrowLeft } from "lucide-react"; import { requireAdmin } from "@/lib/session"; import { getRequestDetail } from "@/lib/queries/admin"; import { formatBytes, formatDate, formatMs, formatUsd } from "@/lib/format"; import { PageHeader } from "@/components/ui/page-header"; import { Badge, StatusBadge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Stat, StatGrid } from "@/components/ui/stat"; import { CodeBlock } from "@/components/ui/code-block"; import { CopyButton } from "@/components/ui/copy-button"; import { Table, TableBody, TableCell, TableEmpty, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { KV, MarginText, Mono, NetworkBadge, Panel, PlanBadge, ProviderBadge, numCell } from "@/components/admin/primitives"; export const dynamic = "force-dynamic"; export default async function AdminRequestDetail({ params }: { params: Promise<{ id: string }> }) { await requireAdmin(); const { id } = await params; const d = await getRequestDetail(id); if (!d) notFound(); const { req } = d; const margin = req.priceUsd - req.costUsd; return ( <>
{req.id} {req.errorCode ? {req.errorCode} : null} {req.cached ? cached : null} } description={ {req.method} {req.url} } actions={ <> {d.org ? ( ) : null} } /> 0 ? (margin / req.priceUsd) * 100 : null} />} />
{d.org.name}{d.org.providerVisibility ? provider debug on : null} : req.organizationId }, { label: "Project", value: d.project ? `${d.project.name} (${d.project.environment})` : req.projectId }, { label: "API key", value: d.key ? {d.key.name} {d.key.keyPrefix}…{d.key.last4} : req.source === "playground" ? "— (playground)" : "—" }, { label: "Source", value: req.source }, { label: "URL", value: {req.url}, mono: true, span: true }, { label: "Final URL", value: req.finalUrl ? {req.finalUrl} : "—", mono: true, span: true }, { label: "Domain", value: req.domain, mono: true }, { label: "Method", value: req.method, mono: true }, { label: "Requested network", value: req.requestedNetwork }, { label: "Resolved network", value: }, { label: "Geo", value: [req.country, req.region, req.city].filter(Boolean).join(" / ") || "—", mono: true }, { label: "Session", value: req.sessionId ?? "—", mono: true }, { label: "Browser", value: req.browser ? "requested" : "no" }, { label: "Format", value: req.format }, { label: "Client IP", value: req.clientIp ?? "—", mono: true }, { label: "User agent", value: req.userAgent ?? "—", span: true }, { label: "Created", value: formatDate(req.createdAt) }, { label: "Completed", value: req.completedAt ? formatDate(req.completedAt) : "—" }, { label: "Error message", value: req.errorMessage ?? "—", span: true }, ]} />
{req.timing && Object.keys(req.timing).length ? ( ({ label: k, value: formatMs(v), mono: true }))} /> ) : (

No timing recorded.

)}
{d.session ? ( }, { label: "Network", value: }, { label: "Status", value: }, { label: "Requests", value: d.session.requestCount }, { label: "Expires", value: formatDate(d.session.expiresAt) }, ]} /> ) : null} Metric Quantity Price Upstream {d.usage.length === 0 ? ( No usage events (free-tier or failed before metering). ) : ( d.usage.map((u) => ( {u.metric} {u.unit === "bytes" ? formatBytes(u.quantity) : `${u.quantity} ${u.unit}`} {formatUsd(u.costUsd, true)} {formatUsd(u.upstreamCostUsd, true)} )) )}
# Provider Network Geo Outcome HTTP Error / block reason Score Duration Bytes $/GB Cost {d.attempts.length === 0 ? ( No attempts recorded (request rejected before routing). ) : ( d.attempts.map((a) => ( {a.attemptNo} {a.country ?? "—"} {a.sessionKey ?
sticky
: null}
{a.httpStatus ?? "—"} {a.errorCode ?
{a.errorCode}
: null} {a.blockReason ?
block: {a.blockReason}
: null} {a.errorDetail ? (
{a.errorDetail}
) : null} {!a.errorCode && !a.blockReason && !a.errorDetail ? — : null}
{a.routingScore !== null ? a.routingScore.toFixed(3) : "—"} {formatMs(a.durationMs)} {formatBytes(a.bytesIn + a.bytesOut)} {a.unitPricePerGb ? `$${a.unitPricePerGb}` : "—"} {formatUsd(a.costUsd, true)}
)) )}
{d.attempts.some((a) => a.timing) ? ( ({ attempt: a.attemptNo, provider: a.provider, timing: a.timing })), null, 2)} lang="json" maxHeight={320} /> ) : null} ); }